//! 流程通用基础信息

use serde::{Deserialize, Serialize};
use serde_json::Value;

/// 流程信息
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct WorkflowBaseInfo {
    pub form_id: String,
    pub workflow_id: String,
    pub workflow_name: String,
    pub workflow_type_id: String,
    pub workflow_type_name: String,
}

/// 流程意见
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct WorkflowRequestLog {
    pub annex_doc_htmls: String,
    pub id: String,
    pub node_id: String,
    pub node_name: String,
    pub operate_date: String,
    pub operate_time: String,
    pub operate_type: String,
    pub operator_dept: String,
    pub operator_id: String,
    pub operator_name: String,
    pub received_persons: String,
    pub remark: String,
    pub sign_doc_htmls: String,
    pub sign_work_flow_htmls: String,
}

/// 流程表单内容
///
/// 主表和明细表都用此struct解析，解析主表或者明细表的每个字段机器对应的数据。
///
/// 此实现了default。使用时需注意相关字段的值是否正确。
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct WorkflowRequestTableField {
    pub browserurl: String,
    pub edit: bool,
    #[serde(rename = "fieldDBType")]
    pub field_dbtype: String,
    pub field_form_name: String,
    pub field_html_type: String,
    pub field_id: String,
    pub field_name: String,
    pub field_order: i64,
    pub field_show_name: String,
    pub field_show_value: String,
    pub field_type: String,
    pub field_value: String,
    pub filed_html_show: String,
    pub mand: bool,
    pub view: bool,
    pub selectnames: Vec<Value>,
    pub selectvalues: Vec<Value>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct WorkflowRequestTableRecord {
    pub record_order: i64,
    pub workflow_request_table_fields: Vec<WorkflowRequestTableField>,
}

/// 流程明细表数据
///
/// 解析明细表的数据。
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct WorkflowDetailTableInfo {
    #[serde(rename = "tableDBName")]
    pub table_dbname: String,
    pub table_field_name: Vec<String>,
    pub table_title: String,
    pub workflow_request_table_records: Vec<WorkflowRequestTableRecord>,
}

/// 流程主表数据
///
/// 解析明细表的数据。
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct WorkflowMainTableInfo {
    pub request_records: Vec<WorkflowRequestTableRecord>,
    #[serde(rename = "tableDBName")]
    pub table_dbname: String,
}

/// 接口异常信息
///
/// 例如状态为PARAM_ERROR 则返回错误参数信息
///
/// // TODO: 待获取详细信息。
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct ErrMsg {
    #[serde(flatten)]
    pub msg: Value,
}
